{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Extracting MNIST_data\\train-images-idx3-ubyte.gz\n",
      "Extracting MNIST_data\\train-labels-idx1-ubyte.gz\n",
      "Extracting MNIST_data\\t10k-images-idx3-ubyte.gz\n",
      "Extracting MNIST_data\\t10k-labels-idx1-ubyte.gz\n",
      "in iteration 0the accuracy is : 0.1661\n",
      "in iteration 1the accuracy is : 0.1918\n",
      "in iteration 2the accuracy is : 0.2136\n",
      "in iteration 3the accuracy is : 0.2329\n",
      "in iteration 4the accuracy is : 0.2499\n",
      "in iteration 5the accuracy is : 0.2652\n",
      "in iteration 6the accuracy is : 0.2792\n",
      "in iteration 7the accuracy is : 0.29\n",
      "in iteration 8the accuracy is : 0.3024\n",
      "in iteration 9the accuracy is : 0.3144\n",
      "in iteration 10the accuracy is : 0.3272\n",
      "in iteration 11the accuracy is : 0.338\n",
      "in iteration 12the accuracy is : 0.3501\n",
      "in iteration 13the accuracy is : 0.3607\n",
      "in iteration 14the accuracy is : 0.3712\n",
      "in iteration 15the accuracy is : 0.3855\n",
      "in iteration 16the accuracy is : 0.3974\n",
      "in iteration 17the accuracy is : 0.4068\n",
      "in iteration 18the accuracy is : 0.4178\n",
      "in iteration 19the accuracy is : 0.4291\n",
      "in iteration 20the accuracy is : 0.44\n",
      "in iteration 21the accuracy is : 0.4503\n",
      "in iteration 22the accuracy is : 0.4595\n",
      "in iteration 23the accuracy is : 0.4693\n",
      "in iteration 24the accuracy is : 0.4789\n",
      "in iteration 25the accuracy is : 0.4857\n",
      "in iteration 26the accuracy is : 0.4935\n",
      "in iteration 27the accuracy is : 0.5022\n",
      "in iteration 28the accuracy is : 0.5086\n",
      "in iteration 29the accuracy is : 0.5152\n",
      "in iteration 30the accuracy is : 0.5221\n",
      "in iteration 31the accuracy is : 0.5294\n",
      "in iteration 32the accuracy is : 0.5355\n",
      "in iteration 33the accuracy is : 0.5417\n",
      "in iteration 34the accuracy is : 0.5488\n",
      "in iteration 35the accuracy is : 0.5558\n",
      "in iteration 36the accuracy is : 0.561\n",
      "in iteration 37the accuracy is : 0.5667\n",
      "in iteration 38the accuracy is : 0.5729\n",
      "in iteration 39the accuracy is : 0.5776\n",
      "in iteration 40the accuracy is : 0.5832\n",
      "in iteration 41the accuracy is : 0.5875\n",
      "in iteration 42the accuracy is : 0.5919\n",
      "in iteration 43the accuracy is : 0.5957\n",
      "in iteration 44the accuracy is : 0.6011\n",
      "in iteration 45the accuracy is : 0.6075\n",
      "in iteration 46the accuracy is : 0.6108\n",
      "in iteration 47the accuracy is : 0.6138\n",
      "in iteration 48the accuracy is : 0.6178\n",
      "in iteration 49the accuracy is : 0.6204\n",
      "in iteration 50the accuracy is : 0.6221\n",
      "in iteration 51the accuracy is : 0.625\n",
      "in iteration 52the accuracy is : 0.6284\n",
      "in iteration 53the accuracy is : 0.631\n",
      "in iteration 54the accuracy is : 0.635\n",
      "in iteration 55the accuracy is : 0.638\n",
      "in iteration 56the accuracy is : 0.6403\n",
      "in iteration 57the accuracy is : 0.6428\n",
      "in iteration 58the accuracy is : 0.6451\n",
      "in iteration 59the accuracy is : 0.6478\n",
      "in iteration 60the accuracy is : 0.6511\n",
      "in iteration 61the accuracy is : 0.654\n",
      "in iteration 62the accuracy is : 0.6568\n",
      "in iteration 63the accuracy is : 0.6582\n",
      "in iteration 64the accuracy is : 0.6594\n",
      "in iteration 65the accuracy is : 0.6615\n",
      "in iteration 66the accuracy is : 0.6627\n",
      "in iteration 67the accuracy is : 0.6644\n",
      "in iteration 68the accuracy is : 0.6658\n",
      "in iteration 69the accuracy is : 0.6678\n",
      "in iteration 70the accuracy is : 0.6698\n",
      "in iteration 71the accuracy is : 0.672\n",
      "in iteration 72the accuracy is : 0.6738\n",
      "in iteration 73the accuracy is : 0.6759\n",
      "in iteration 74the accuracy is : 0.6774\n",
      "in iteration 75the accuracy is : 0.6782\n",
      "in iteration 76the accuracy is : 0.6805\n",
      "in iteration 77the accuracy is : 0.6818\n",
      "in iteration 78the accuracy is : 0.6828\n",
      "in iteration 79the accuracy is : 0.6846\n",
      "in iteration 80the accuracy is : 0.6861\n",
      "in iteration 81the accuracy is : 0.6868\n",
      "in iteration 82the accuracy is : 0.6888\n",
      "in iteration 83the accuracy is : 0.6899\n",
      "in iteration 84the accuracy is : 0.6914\n",
      "in iteration 85the accuracy is : 0.6932\n",
      "in iteration 86the accuracy is : 0.6941\n",
      "in iteration 87the accuracy is : 0.6952\n",
      "in iteration 88the accuracy is : 0.6964\n",
      "in iteration 89the accuracy is : 0.6976\n",
      "in iteration 90the accuracy is : 0.6987\n",
      "in iteration 91the accuracy is : 0.6992\n",
      "in iteration 92the accuracy is : 0.7001\n",
      "in iteration 93the accuracy is : 0.7008\n",
      "in iteration 94the accuracy is : 0.7026\n",
      "in iteration 95the accuracy is : 0.7039\n",
      "in iteration 96the accuracy is : 0.7054\n",
      "in iteration 97the accuracy is : 0.7062\n",
      "in iteration 98the accuracy is : 0.7072\n",
      "in iteration 99the accuracy is : 0.7078\n",
      "in iteration 100the accuracy is : 0.7088\n",
      "in iteration 101the accuracy is : 0.7097\n",
      "in iteration 102the accuracy is : 0.7106\n",
      "in iteration 103the accuracy is : 0.7116\n",
      "in iteration 104the accuracy is : 0.7125\n",
      "in iteration 105the accuracy is : 0.7128\n",
      "in iteration 106the accuracy is : 0.7137\n",
      "in iteration 107the accuracy is : 0.7152\n",
      "in iteration 108the accuracy is : 0.716\n",
      "in iteration 109the accuracy is : 0.7166\n",
      "in iteration 110the accuracy is : 0.717\n",
      "in iteration 111the accuracy is : 0.7176\n",
      "in iteration 112the accuracy is : 0.7182\n",
      "in iteration 113the accuracy is : 0.7189\n",
      "in iteration 114the accuracy is : 0.7195\n",
      "in iteration 115the accuracy is : 0.7207\n",
      "in iteration 116the accuracy is : 0.7215\n",
      "in iteration 117the accuracy is : 0.7223\n",
      "in iteration 118the accuracy is : 0.7236\n",
      "in iteration 119the accuracy is : 0.7246\n",
      "in iteration 120the accuracy is : 0.7252\n",
      "in iteration 121the accuracy is : 0.7264\n",
      "in iteration 122the accuracy is : 0.7271\n",
      "in iteration 123the accuracy is : 0.7283\n",
      "in iteration 124the accuracy is : 0.729\n",
      "in iteration 125the accuracy is : 0.7301\n",
      "in iteration 126the accuracy is : 0.7314\n",
      "in iteration 127the accuracy is : 0.732\n",
      "in iteration 128the accuracy is : 0.7328\n",
      "in iteration 129the accuracy is : 0.7344\n",
      "in iteration 130the accuracy is : 0.7352\n",
      "in iteration 131the accuracy is : 0.7362\n",
      "in iteration 132the accuracy is : 0.7376\n",
      "in iteration 133the accuracy is : 0.7385\n",
      "in iteration 134the accuracy is : 0.7401\n",
      "in iteration 135the accuracy is : 0.7413\n",
      "in iteration 136the accuracy is : 0.7426\n",
      "in iteration 137the accuracy is : 0.7441\n",
      "in iteration 138the accuracy is : 0.745\n",
      "in iteration 139the accuracy is : 0.7464\n",
      "in iteration 140the accuracy is : 0.747\n",
      "in iteration 141the accuracy is : 0.7485\n",
      "in iteration 142the accuracy is : 0.7489\n",
      "in iteration 143the accuracy is : 0.75\n",
      "in iteration 144the accuracy is : 0.7509\n",
      "in iteration 145the accuracy is : 0.7524\n",
      "in iteration 146the accuracy is : 0.7531\n",
      "in iteration 147the accuracy is : 0.7541\n",
      "in iteration 148the accuracy is : 0.7552\n",
      "in iteration 149the accuracy is : 0.7557\n",
      "in iteration 150the accuracy is : 0.757\n",
      "in iteration 151the accuracy is : 0.7572\n",
      "in iteration 152the accuracy is : 0.7581\n",
      "in iteration 153the accuracy is : 0.7588\n",
      "in iteration 154the accuracy is : 0.7591\n",
      "in iteration 155the accuracy is : 0.7594\n",
      "in iteration 156the accuracy is : 0.7601\n",
      "in iteration 157the accuracy is : 0.7605\n",
      "in iteration 158the accuracy is : 0.7613\n",
      "in iteration 159the accuracy is : 0.7615\n",
      "in iteration 160the accuracy is : 0.7625\n",
      "in iteration 161the accuracy is : 0.763\n",
      "in iteration 162the accuracy is : 0.7638\n",
      "in iteration 163the accuracy is : 0.7642\n",
      "in iteration 164the accuracy is : 0.7655\n",
      "in iteration 165the accuracy is : 0.7665\n",
      "in iteration 166the accuracy is : 0.7667\n",
      "in iteration 167the accuracy is : 0.7673\n",
      "in iteration 168the accuracy is : 0.7676\n",
      "in iteration 169the accuracy is : 0.768\n",
      "in iteration 170the accuracy is : 0.7688\n",
      "in iteration 171the accuracy is : 0.7697\n",
      "in iteration 172the accuracy is : 0.77\n",
      "in iteration 173the accuracy is : 0.7705\n",
      "in iteration 174the accuracy is : 0.7705\n",
      "in iteration 175the accuracy is : 0.7707\n",
      "in iteration 176the accuracy is : 0.7712\n",
      "in iteration 177the accuracy is : 0.7721\n",
      "in iteration 178the accuracy is : 0.7725\n",
      "in iteration 179the accuracy is : 0.7727\n",
      "in iteration 180the accuracy is : 0.7734\n",
      "in iteration 181the accuracy is : 0.7737\n",
      "in iteration 182the accuracy is : 0.7739\n",
      "in iteration 183the accuracy is : 0.7743\n",
      "in iteration 184the accuracy is : 0.7753\n",
      "in iteration 185the accuracy is : 0.7756\n",
      "in iteration 186the accuracy is : 0.7759\n",
      "in iteration 187the accuracy is : 0.7757\n",
      "in iteration 188the accuracy is : 0.7769\n",
      "in iteration 189the accuracy is : 0.7771\n",
      "in iteration 190the accuracy is : 0.7772\n",
      "in iteration 191the accuracy is : 0.7779\n",
      "in iteration 192the accuracy is : 0.7779\n",
      "in iteration 193the accuracy is : 0.7779\n",
      "in iteration 194the accuracy is : 0.7785\n",
      "in iteration 195the accuracy is : 0.7787\n",
      "in iteration 196the accuracy is : 0.779\n",
      "in iteration 197the accuracy is : 0.7795\n",
      "in iteration 198the accuracy is : 0.78\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in iteration 199the accuracy is : 0.7801\n",
      "in iteration 200the accuracy is : 0.7802\n",
      "in iteration 201the accuracy is : 0.7803\n",
      "in iteration 202the accuracy is : 0.7805\n",
      "in iteration 203the accuracy is : 0.7806\n",
      "in iteration 204the accuracy is : 0.781\n",
      "in iteration 205the accuracy is : 0.7813\n",
      "in iteration 206the accuracy is : 0.7815\n",
      "in iteration 207the accuracy is : 0.7816\n",
      "in iteration 208the accuracy is : 0.7818\n",
      "in iteration 209the accuracy is : 0.7821\n",
      "in iteration 210the accuracy is : 0.7823\n",
      "in iteration 211the accuracy is : 0.7822\n",
      "in iteration 212the accuracy is : 0.7824\n",
      "in iteration 213the accuracy is : 0.7827\n",
      "in iteration 214the accuracy is : 0.7827\n",
      "in iteration 215the accuracy is : 0.7832\n",
      "in iteration 216the accuracy is : 0.7837\n",
      "in iteration 217the accuracy is : 0.7837\n",
      "in iteration 218the accuracy is : 0.7838\n",
      "in iteration 219the accuracy is : 0.7838\n",
      "in iteration 220the accuracy is : 0.7842\n",
      "in iteration 221the accuracy is : 0.7843\n",
      "in iteration 222the accuracy is : 0.7846\n",
      "in iteration 223the accuracy is : 0.785\n",
      "in iteration 224the accuracy is : 0.7851\n",
      "in iteration 225the accuracy is : 0.7853\n",
      "in iteration 226the accuracy is : 0.7852\n",
      "in iteration 227the accuracy is : 0.7858\n",
      "in iteration 228the accuracy is : 0.786\n",
      "in iteration 229the accuracy is : 0.7862\n",
      "in iteration 230the accuracy is : 0.786\n",
      "in iteration 231the accuracy is : 0.7863\n",
      "in iteration 232the accuracy is : 0.7866\n",
      "in iteration 233the accuracy is : 0.7866\n",
      "in iteration 234the accuracy is : 0.7871\n",
      "in iteration 235the accuracy is : 0.7871\n",
      "in iteration 236the accuracy is : 0.7871\n",
      "in iteration 237the accuracy is : 0.7872\n",
      "in iteration 238the accuracy is : 0.7873\n",
      "in iteration 239the accuracy is : 0.7877\n",
      "in iteration 240the accuracy is : 0.788\n",
      "in iteration 241the accuracy is : 0.788\n",
      "in iteration 242the accuracy is : 0.7882\n",
      "in iteration 243the accuracy is : 0.7884\n",
      "in iteration 244the accuracy is : 0.7884\n",
      "in iteration 245the accuracy is : 0.7884\n",
      "in iteration 246the accuracy is : 0.7885\n",
      "in iteration 247the accuracy is : 0.7887\n",
      "in iteration 248the accuracy is : 0.7891\n",
      "in iteration 249the accuracy is : 0.7894\n",
      "in iteration 250the accuracy is : 0.7896\n",
      "in iteration 251the accuracy is : 0.7901\n",
      "in iteration 252the accuracy is : 0.7901\n",
      "in iteration 253the accuracy is : 0.7902\n",
      "in iteration 254the accuracy is : 0.7904\n",
      "in iteration 255the accuracy is : 0.7907\n",
      "in iteration 256the accuracy is : 0.7909\n",
      "in iteration 257the accuracy is : 0.7909\n",
      "in iteration 258the accuracy is : 0.791\n",
      "in iteration 259the accuracy is : 0.791\n",
      "in iteration 260the accuracy is : 0.7914\n",
      "in iteration 261the accuracy is : 0.7911\n",
      "in iteration 262the accuracy is : 0.7913\n",
      "in iteration 263the accuracy is : 0.7914\n",
      "in iteration 264the accuracy is : 0.7916\n",
      "in iteration 265the accuracy is : 0.7921\n",
      "in iteration 266the accuracy is : 0.792\n",
      "in iteration 267the accuracy is : 0.7926\n",
      "in iteration 268the accuracy is : 0.7928\n",
      "in iteration 269the accuracy is : 0.7932\n",
      "in iteration 270the accuracy is : 0.7934\n",
      "in iteration 271the accuracy is : 0.7935\n",
      "in iteration 272the accuracy is : 0.7938\n",
      "in iteration 273the accuracy is : 0.7942\n",
      "in iteration 274the accuracy is : 0.7942\n",
      "in iteration 275the accuracy is : 0.7948\n",
      "in iteration 276the accuracy is : 0.7952\n",
      "in iteration 277the accuracy is : 0.7955\n",
      "in iteration 278the accuracy is : 0.7961\n",
      "in iteration 279the accuracy is : 0.7969\n",
      "in iteration 280the accuracy is : 0.7974\n",
      "in iteration 281the accuracy is : 0.7981\n",
      "in iteration 282the accuracy is : 0.7996\n",
      "in iteration 283the accuracy is : 0.8007\n",
      "in iteration 284the accuracy is : 0.8033\n",
      "in iteration 285the accuracy is : 0.8043\n",
      "in iteration 286the accuracy is : 0.8062\n",
      "in iteration 287the accuracy is : 0.8102\n",
      "in iteration 288the accuracy is : 0.8131\n",
      "in iteration 289the accuracy is : 0.8162\n",
      "in iteration 290the accuracy is : 0.8199\n",
      "in iteration 291the accuracy is : 0.8227\n",
      "in iteration 292the accuracy is : 0.8273\n",
      "in iteration 293the accuracy is : 0.8303\n",
      "in iteration 294the accuracy is : 0.8335\n",
      "in iteration 295the accuracy is : 0.8368\n",
      "in iteration 296the accuracy is : 0.8403\n",
      "in iteration 297the accuracy is : 0.8431\n",
      "in iteration 298the accuracy is : 0.8455\n",
      "in iteration 299the accuracy is : 0.8471\n",
      "in iteration 300the accuracy is : 0.8496\n",
      "in iteration 301the accuracy is : 0.8516\n",
      "in iteration 302the accuracy is : 0.8529\n",
      "in iteration 303the accuracy is : 0.8542\n",
      "in iteration 304the accuracy is : 0.856\n",
      "in iteration 305the accuracy is : 0.8567\n",
      "in iteration 306the accuracy is : 0.8584\n",
      "in iteration 307the accuracy is : 0.8598\n",
      "in iteration 308the accuracy is : 0.8606\n",
      "in iteration 309the accuracy is : 0.8611\n",
      "in iteration 310the accuracy is : 0.8618\n",
      "in iteration 311the accuracy is : 0.8633\n",
      "in iteration 312the accuracy is : 0.8641\n",
      "in iteration 313the accuracy is : 0.8655\n",
      "in iteration 314the accuracy is : 0.8665\n",
      "in iteration 315the accuracy is : 0.8673\n",
      "in iteration 316the accuracy is : 0.868\n",
      "in iteration 317the accuracy is : 0.8682\n",
      "in iteration 318the accuracy is : 0.8682\n",
      "in iteration 319the accuracy is : 0.8691\n",
      "in iteration 320the accuracy is : 0.8703\n",
      "in iteration 321the accuracy is : 0.8705\n",
      "in iteration 322the accuracy is : 0.8712\n",
      "in iteration 323the accuracy is : 0.8716\n",
      "in iteration 324the accuracy is : 0.8718\n",
      "in iteration 325the accuracy is : 0.8726\n",
      "in iteration 326the accuracy is : 0.873\n",
      "in iteration 327the accuracy is : 0.8731\n",
      "in iteration 328the accuracy is : 0.8733\n",
      "in iteration 329the accuracy is : 0.874\n",
      "in iteration 330the accuracy is : 0.874\n",
      "in iteration 331the accuracy is : 0.8745\n",
      "in iteration 332the accuracy is : 0.8748\n",
      "in iteration 333the accuracy is : 0.8756\n",
      "in iteration 334the accuracy is : 0.8755\n",
      "in iteration 335the accuracy is : 0.8757\n",
      "in iteration 336the accuracy is : 0.8757\n",
      "in iteration 337the accuracy is : 0.876\n",
      "in iteration 338the accuracy is : 0.8764\n",
      "in iteration 339the accuracy is : 0.8762\n",
      "in iteration 340the accuracy is : 0.8766\n",
      "in iteration 341the accuracy is : 0.8768\n",
      "in iteration 342the accuracy is : 0.8776\n",
      "in iteration 343the accuracy is : 0.8775\n",
      "in iteration 344the accuracy is : 0.8773\n",
      "in iteration 345the accuracy is : 0.8776\n",
      "in iteration 346the accuracy is : 0.8777\n",
      "in iteration 347the accuracy is : 0.8777\n",
      "in iteration 348the accuracy is : 0.8776\n",
      "in iteration 349the accuracy is : 0.8781\n",
      "in iteration 350the accuracy is : 0.8781\n",
      "in iteration 351the accuracy is : 0.8784\n",
      "in iteration 352the accuracy is : 0.8787\n",
      "in iteration 353the accuracy is : 0.8788\n",
      "in iteration 354the accuracy is : 0.8792\n",
      "in iteration 355the accuracy is : 0.8795\n",
      "in iteration 356the accuracy is : 0.8796\n",
      "in iteration 357the accuracy is : 0.8797\n",
      "in iteration 358the accuracy is : 0.88\n",
      "in iteration 359the accuracy is : 0.88\n",
      "in iteration 360the accuracy is : 0.8801\n",
      "in iteration 361the accuracy is : 0.8802\n",
      "in iteration 362the accuracy is : 0.8804\n",
      "in iteration 363the accuracy is : 0.8806\n",
      "in iteration 364the accuracy is : 0.8809\n",
      "in iteration 365the accuracy is : 0.8814\n",
      "in iteration 366the accuracy is : 0.8816\n",
      "in iteration 367the accuracy is : 0.8818\n",
      "in iteration 368the accuracy is : 0.8821\n",
      "in iteration 369the accuracy is : 0.8818\n",
      "in iteration 370the accuracy is : 0.8819\n",
      "in iteration 371the accuracy is : 0.8825\n",
      "in iteration 372the accuracy is : 0.8825\n",
      "in iteration 373the accuracy is : 0.8827\n",
      "in iteration 374the accuracy is : 0.8829\n",
      "in iteration 375the accuracy is : 0.8828\n",
      "in iteration 376the accuracy is : 0.883\n",
      "in iteration 377the accuracy is : 0.8832\n",
      "in iteration 378the accuracy is : 0.8834\n",
      "in iteration 379the accuracy is : 0.8837\n",
      "in iteration 380the accuracy is : 0.8837\n",
      "in iteration 381the accuracy is : 0.8839\n",
      "in iteration 382the accuracy is : 0.8844\n",
      "in iteration 383the accuracy is : 0.8844\n",
      "in iteration 384the accuracy is : 0.8849\n",
      "in iteration 385the accuracy is : 0.8851\n",
      "in iteration 386the accuracy is : 0.8852\n",
      "in iteration 387the accuracy is : 0.8854\n",
      "in iteration 388the accuracy is : 0.8857\n",
      "in iteration 389the accuracy is : 0.8858\n",
      "in iteration 390the accuracy is : 0.886\n",
      "in iteration 391the accuracy is : 0.8859\n",
      "in iteration 392the accuracy is : 0.8864\n",
      "in iteration 393the accuracy is : 0.8863\n",
      "in iteration 394the accuracy is : 0.8865\n",
      "in iteration 395the accuracy is : 0.8865\n",
      "in iteration 396the accuracy is : 0.8866\n",
      "in iteration 397the accuracy is : 0.8866\n",
      "in iteration 398the accuracy is : 0.8869\n",
      "in iteration 399the accuracy is : 0.887\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in iteration 400the accuracy is : 0.8872\n",
      "in iteration 401the accuracy is : 0.8873\n",
      "in iteration 402the accuracy is : 0.8876\n",
      "in iteration 403the accuracy is : 0.8874\n",
      "in iteration 404the accuracy is : 0.8876\n",
      "in iteration 405the accuracy is : 0.8878\n",
      "in iteration 406the accuracy is : 0.8878\n",
      "in iteration 407the accuracy is : 0.888\n",
      "in iteration 408the accuracy is : 0.8884\n",
      "in iteration 409the accuracy is : 0.8882\n",
      "in iteration 410the accuracy is : 0.8884\n",
      "in iteration 411the accuracy is : 0.8886\n",
      "in iteration 412the accuracy is : 0.889\n",
      "in iteration 413the accuracy is : 0.8891\n",
      "in iteration 414the accuracy is : 0.8894\n",
      "in iteration 415the accuracy is : 0.8892\n",
      "in iteration 416the accuracy is : 0.8894\n",
      "in iteration 417the accuracy is : 0.8895\n",
      "in iteration 418the accuracy is : 0.8897\n",
      "in iteration 419the accuracy is : 0.89\n",
      "in iteration 420the accuracy is : 0.8901\n",
      "in iteration 421the accuracy is : 0.8902\n",
      "in iteration 422the accuracy is : 0.8903\n",
      "in iteration 423the accuracy is : 0.8905\n",
      "in iteration 424the accuracy is : 0.8904\n",
      "in iteration 425the accuracy is : 0.8906\n",
      "in iteration 426the accuracy is : 0.8906\n",
      "in iteration 427the accuracy is : 0.8908\n",
      "in iteration 428the accuracy is : 0.8909\n",
      "in iteration 429the accuracy is : 0.891\n",
      "in iteration 430the accuracy is : 0.8911\n",
      "in iteration 431the accuracy is : 0.8915\n",
      "in iteration 432the accuracy is : 0.8916\n",
      "in iteration 433the accuracy is : 0.8915\n",
      "in iteration 434the accuracy is : 0.8915\n",
      "in iteration 435the accuracy is : 0.8914\n",
      "in iteration 436the accuracy is : 0.8915\n",
      "in iteration 437the accuracy is : 0.8916\n",
      "in iteration 438the accuracy is : 0.8915\n",
      "in iteration 439the accuracy is : 0.8914\n",
      "in iteration 440the accuracy is : 0.8917\n",
      "in iteration 441the accuracy is : 0.8919\n",
      "in iteration 442the accuracy is : 0.8922\n",
      "in iteration 443the accuracy is : 0.8921\n",
      "in iteration 444the accuracy is : 0.892\n",
      "in iteration 445the accuracy is : 0.8921\n",
      "in iteration 446the accuracy is : 0.8922\n",
      "in iteration 447the accuracy is : 0.8925\n",
      "in iteration 448the accuracy is : 0.8925\n",
      "in iteration 449the accuracy is : 0.8925\n",
      "in iteration 450the accuracy is : 0.8928\n",
      "in iteration 451the accuracy is : 0.893\n",
      "in iteration 452the accuracy is : 0.8929\n",
      "in iteration 453the accuracy is : 0.8931\n",
      "in iteration 454the accuracy is : 0.8931\n",
      "in iteration 455the accuracy is : 0.8931\n",
      "in iteration 456the accuracy is : 0.8934\n",
      "in iteration 457the accuracy is : 0.8934\n",
      "in iteration 458the accuracy is : 0.8939\n",
      "in iteration 459the accuracy is : 0.8939\n",
      "in iteration 460the accuracy is : 0.8939\n",
      "in iteration 461the accuracy is : 0.8939\n",
      "in iteration 462the accuracy is : 0.8941\n",
      "in iteration 463the accuracy is : 0.8939\n",
      "in iteration 464the accuracy is : 0.8941\n",
      "in iteration 465the accuracy is : 0.8941\n",
      "in iteration 466the accuracy is : 0.8941\n",
      "in iteration 467the accuracy is : 0.8941\n",
      "in iteration 468the accuracy is : 0.8942\n",
      "in iteration 469the accuracy is : 0.8942\n",
      "in iteration 470the accuracy is : 0.8941\n",
      "in iteration 471the accuracy is : 0.8943\n",
      "in iteration 472the accuracy is : 0.8942\n",
      "in iteration 473the accuracy is : 0.8942\n",
      "in iteration 474the accuracy is : 0.8942\n",
      "in iteration 475the accuracy is : 0.8943\n",
      "in iteration 476the accuracy is : 0.8944\n",
      "in iteration 477the accuracy is : 0.8942\n",
      "in iteration 478the accuracy is : 0.8944\n",
      "in iteration 479the accuracy is : 0.8945\n",
      "in iteration 480the accuracy is : 0.8946\n",
      "in iteration 481the accuracy is : 0.8949\n",
      "in iteration 482the accuracy is : 0.8949\n",
      "in iteration 483the accuracy is : 0.8949\n",
      "in iteration 484the accuracy is : 0.895\n",
      "in iteration 485the accuracy is : 0.8952\n",
      "in iteration 486the accuracy is : 0.8953\n",
      "in iteration 487the accuracy is : 0.8953\n",
      "in iteration 488the accuracy is : 0.8954\n",
      "in iteration 489the accuracy is : 0.8954\n",
      "in iteration 490the accuracy is : 0.8955\n",
      "in iteration 491the accuracy is : 0.8955\n",
      "in iteration 492the accuracy is : 0.8955\n",
      "in iteration 493the accuracy is : 0.8954\n",
      "in iteration 494the accuracy is : 0.8954\n",
      "in iteration 495the accuracy is : 0.8957\n",
      "in iteration 496the accuracy is : 0.8955\n",
      "in iteration 497the accuracy is : 0.8961\n",
      "in iteration 498the accuracy is : 0.8958\n",
      "in iteration 499the accuracy is : 0.8958\n"
     ]
    }
   ],
   "source": [
    "# 数据集介绍\n",
    "# MNIST数据集，100k的训练数据，10k的预测数据，数据由tensorflow中的examples.tutorials.mnist读取 \n",
    "# 数据集介绍：：Yann LeCun's website\n",
    "# 由28*28的像素组成输入特征，输出特征为0-9的数字\n",
    "\n",
    "# 可调节参数：\n",
    "# --------\n",
    "# batch_size, initial_weight,二次损失函数,learning_rate,epoch_n\n",
    "# --------\n",
    "\n",
    "import tensorflow as tf\n",
    "from tensorflow.examples.tutorials.mnist import input_data\n",
    "\n",
    "mnist = input_data.read_data_sets(\"MNIST_data\", one_hot = True)\n",
    "\n",
    "# mini_batch的大小\n",
    "batch_size = 100\n",
    "batch_n = mnist.train.num_examples // batch_size\n",
    "\n",
    "# # 定义两个placeholder用来feed数据，分别代表x和y --784列和10列(one-hot)\n",
    "x = tf.placeholder(tf.float32, [None, 784])\n",
    "y = tf.placeholder(tf.float32, [None, 10])\n",
    "\n",
    "# # ----\n",
    "# # 构建多分类回归\n",
    "\n",
    "# # 定义weight和bias，初始化分别为正态随机和0.0\n",
    "initial_weight = tf.random_normal([784, 10])\n",
    "weight = tf.Variable(initial_weight)\n",
    "bias = tf.Variable(tf.zeros([10]))\n",
    "a = tf.matmul(x, weight) + bias\n",
    "y_head = tf.nn.softmax(a)\n",
    "\n",
    "# # 定义二次损失函数并依据梯度下降法进行训练 -- 这样梯度下降的train就变成了x和y的函数\n",
    "learning_rate = 0.1\n",
    "loss = tf.reduce_mean(tf.square(y - y_head))\n",
    "optimizer = tf.train.GradientDescentOptimizer(learning_rate)\n",
    "train = optimizer.minimize(loss)\n",
    "\n",
    "init = tf.global_variables_initializer()\n",
    "\n",
    "correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_head, 1)) # tf.argmax找到x中等于1的最大的id\n",
    "correction = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) # tf.cast 转换类型，将bool转为float，从而求得准确率\n",
    "\n",
    "# 迭代500次，进行mini_batch梯度下降\n",
    "epoch_n = 500\n",
    "with tf.Session() as session:\n",
    "    session.run(init)\n",
    "    for step in range(epoch_n):\n",
    "        for batch in range(batch_n):\n",
    "            batch_x, batch_y = mnist.train.next_batch(batch_size)\n",
    "            session.run(train, feed_dict= {x: batch_x, y: batch_y}) # 此处是最小化\n",
    "        corr = session.run(correction, feed_dict= {x: mnist.test.images, y: mnist.test.labels}) # 基于测试集对准确率进行测试\n",
    "        print(\"in iteration \" + str(step) + \"the accuracy is : \" + str(corr)) # 打印准确率\n",
    "# 这里看似有问题，其实没问题，因为图没变，DAG对输入的batch依次执行梯度下降法，\n",
    "# 并执行epoch_n个周期，权重会更新epoch_n * batch_n次\n",
    "    \n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
